﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL.RF.JointingCheck;
using Model.RF.JointingCheck;

namespace DAL.RF.JointingCheck
{
    public class JointingFailure_Q : IJointingFailure_Q
    {
        #region 静态变量部分
        private const string PARM_TEST_CUSTOMERID = "@CustomerID";
        private const string PARM_TEST_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_TEST_STARTTIME = "@starttime";
        private const string PARM_TEST_STOPTIME = "@stoptime";
        #endregion


        #region 数据检索部分
        public IList<JointingFailure_QInfo> GetJointingFailure_Q_byDT(string spname, DateTime starttime, DateTime stoptime)
        {
            IList<JointingFailure_QInfo> t_qs = new List<JointingFailure_QInfo>();
            SqlParameter[] testParms = GetDTParameters();
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    JointingFailure_QInfo t_q = new JointingFailure_QInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetDecimal(2));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_JointingCheckbyDT(DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byDT("JointingCheck_StatisticbyDT", starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_QCFixedCheckbyDT(DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byDT("QCFixedCheck_StatisticbyDT", starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_PackCheckbyDT(DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byDT("QCPackCheck_StatisticbyDT", starttime, stoptime);
        }


        public IList<JointingFailure_QInfo> GetJointingFailure_Q_byPIDDT(string spname, string productTypeID, DateTime starttime, DateTime stoptime)
        {
            IList<JointingFailure_QInfo> t_qs = new List<JointingFailure_QInfo>();
            SqlParameter[] testParms = GetPIDDTParameters();
            testParms[0].Value = productTypeID;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    JointingFailure_QInfo t_q = new JointingFailure_QInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetDecimal(2));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_JointingCheckbyPIDDT(string productTypeID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byPIDDT("JointingCheck_StatisticbyPIDDT", productTypeID, starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_QCFixedCheckbyPIDDT(string productTypeID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byPIDDT("QCFixedCheck_StatisticbyPIDDT", productTypeID, starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_PackCheckbyPIDDT(string productTypeID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byPIDDT("QCPackCheck_StatisticbyPIDDT", productTypeID, starttime, stoptime);
        }


        public IList<JointingFailure_QInfo> GetJointingFailure_Q_byCIDDT(string spname, string customerID, DateTime starttime, DateTime stoptime)
        {
            IList<JointingFailure_QInfo> t_qs = new List<JointingFailure_QInfo>();
            SqlParameter[] testParms = GetCIDDTParameters();
            testParms[0].Value = customerID;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    JointingFailure_QInfo t_q = new JointingFailure_QInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetDecimal(2));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_JointingCheckbyCIDDT(string customerID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byCIDDT("JointingCheck_StatisticbyCIDDT", customerID, starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_QCFixedCheckbyCIDDT(string customerID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byCIDDT("QCFixedCheck_StatisticbyCIDDT", customerID, starttime, stoptime);
        }

        public IList<JointingFailure_QInfo> GetJointingFailure_Q_PackCheckbyCIDDT(string customerID, DateTime starttime, DateTime stoptime)
        {
            return GetJointingFailure_Q_byCIDDT("QCFixedCheck_StatisticbyCIDDT", customerID, starttime, stoptime);
        }


        #endregion

        #region 参数部分
        private static SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)             
                };
            return parms;
        }

        public SqlParameter[] GetIDDTParameters(string parameterName)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(parameterName, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime,8),
                    new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime,8),
                };
            return parms;
        }

        public SqlParameter[] GetPIDDTParameters()
        {
            return GetIDDTParameters(PARM_TEST_PRODUCTTYPEID);
        }

        public SqlParameter[] GetCIDDTParameters()
        {
            return GetIDDTParameters(PARM_TEST_CUSTOMERID);
        }

        #endregion
    }
}
